<?php
class StudentOrderAction extends CommonAction {
	
	
	/**
	 * 查询(non-PHPdoc)
	 * @see CommonAction::read()
	 */
	public function read() {
		$map = " 1=1 ";
		
		if(!empty($_POST['XS_XX'])) {
			$map = $map." and student.XS_XX = '".$_POST['XS_XX']."'";
		}
		if(!empty($_POST['XS_NJ'])) {
			$map = $map." and student.XS_NJ = '".$_POST['XS_NJ']."'";
		}
		if(!empty($_POST['XS_BJ'])) {
			$map = $map." and student.XS_BJ = '".$_POST['XS_BJ']."'";
		}
		if(!empty($_POST['DD_DDZT'])) {
			$map = $map." and dd.DD_DDZT = '".$_POST['DD_DDZT']."'";
		}		
		
		$xqid =  $_SESSION['XqFilterString'] ;//获取用户当前拥有校区权限
		if(!empty($xqid)){
			$map = $map." and student.XS_XQ in (".$xqid.") ";
		}
				
		if((!empty($_POST['DD_CJSJ_BEGIN']))&&(!empty($_POST['DD_CJSJ_END']))) {
			$map = $map." and dd.DD_CJSJ between '".$_POST['DD_CJSJ_BEGIN']."' and '".$_POST['DD_CJSJ_END']."'";
		}
		
		$map = $map." and student.XS_ZT = 'xszt1' ";
		$pagenum = isset ( $_POST ['page'] ) ? intval ( $_POST ['page'] ) : 1;
		$rowsnum = isset ( $_POST ['rows'] ) ? intval ( $_POST ['rows'] ) : 10;
		$Student = M ( "Student" );

		$arrNum = $Student->query("select count(DISTINCT dd.DD_KHBH) as num from smis_order dd left join smis_student student on dd.DD_KHBH = student.XS_XH where 1=1 and " . $map);
		$row = $arrNum[0]['num'];
		$total = $row;	

		$studentList = array ();
		$studentList = $Student->table('smis_order dd')
								->join('smis_student student on dd.DD_KHBH  =  student.XS_XH')
								->join('smis_dictionary_list dictionary  on student.XS_NJ = dictionary.ITEM_KEY')
								->join('smis_dictionary_list dictionary1 on student.XS_XX = dictionary1.ITEM_KEY')
								->join('smis_dictionary_list dictionary2 on student.XS_BJ = dictionary2.ITEM_KEY')
								->where($map)
								->Distinct(true)
								 ->field('student.*,dictionary.ITEM_VALUE as NJ,dictionary1.ITEM_VALUE as XX,dictionary2.ITEM_VALUE as BJ')
								->order('student.id desc' )
								->page($pagenum,$rowsnum)->select();	
			
		$resultJson = json_encode($studentList);
		if($resultJson == "null"){//如果查询结果返回为null
			$resultJson = "[]";
		}
		$json = '{"total":' . $total . ',"rows":' . $resultJson . '}'; // 重要，easyui的标准数据格式，数据总数和数据内容在同一个json中
		echo $json;
	}

}
?>
